﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_EhitiseOsaAndmed_response", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENEhitiseOsaAndmedResponse))]
    public class ENEhitiseOsaAndmedResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENEhitiseOsaAndmedResponse clazz;
        
        public ENEhitiseOsaAndmedResponseSerializer(IENEhitiseOsaAndmedResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EN_EhitiseOsaAndmed");
            if (clazz.ENEhitiseOsaAndmed!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa", "http://producers.ehr.xtee.riik.ee/producer/ehr", clazz.ENEhitiseOsaAndmed.Count);
                for (int x = 0; ((clazz.ENEhitiseOsaAndmed != null) 
                            && (x < clazz.ENEhitiseOsaAndmed.Count)); x = (x + 1)) {
                    if (clazz.ENEhitiseOsaAndmed[x]!=null) {
                        Writer.WriteStartElement("ehitise_osa");
                        global::Xtee.Core.SerializationMetadata metaENEhitiseOsaAndmed = this.GetMetaData(clazz.ENEhitiseOsaAndmed[x]);
                        Writer.WriteTypeAttribute(metaENEhitiseOsaAndmed.TypeQualifiedName.Namespace, metaENEhitiseOsaAndmed.TypeQualifiedName.Name);
                        metaENEhitiseOsaAndmed.NewSerializer(clazz.ENEhitiseOsaAndmed[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ENEhitiseOsaAndmed");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EN_EhitiseOsaAndmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed");
                }
                clazz.ENEhitiseOsaAndmed = new System.Collections.Generic.List<ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("EN_EhitiseOsaAndmed");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "ehitise_osa")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa");
                        }
                        global::Xtee.Core.SerializationMetadata metaENEhitiseOsaAndmed = this.GetMetaData<ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType>(Reader, ">>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                        ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType item = metaENEhitiseOsaAndmed.NewEntity<ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType>();
                        clazz.ENEhitiseOsaAndmed.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("ehitise_osa");
                            metaENEhitiseOsaAndmed.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENEhitiseOsaAndmedResponse.ENEhitiseOsaAndmedType))]
        public class ENEhitiseOsaAndmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType clazz;
            
            public ENEhitiseOsaAndmedTypeSerializer(ENEhitiseOsaAndmedResponse.IENEhitiseOsaAndmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.EhosId!=null) {
                    Writer.WriteStartElement("ehos_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.EhosId))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.KltyNkood!=null) {
                    Writer.WriteStartElement("klty_nkood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KltyNkood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.TenaKood!=null) {
                    Writer.WriteStartElement("tena_kood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TenaKood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.TehnNaitNimetus!=null) {
                    Writer.WriteStartElement("tehn_nait_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TehnNaitNimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.JrkNr!=null) {
                    Writer.WriteStartElement("jrk_nr");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.JrkNr))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Lisavaartus!=null) {
                    Writer.WriteStartElement("lisavaartus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lisavaartus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Seotud!=null) {
                    Writer.WriteStartElement("seotud");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Seotud))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DateCreated!=null) {
                    Writer.WriteStartElement("date_created");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DateCreated))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Valistav!=null) {
                    Writer.WriteStartElement("valistav");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Valistav))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Id!=null) {
                    Writer.WriteStartElement("id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Id))).ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="ehos_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>ehos_id");
                    }
                    clazz.EhosId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ehos_id")).Value;
                }
                if (Reader.LocalName=="klty_nkood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>klty_nkood");
                    }
                    clazz.KltyNkood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("klty_nkood")).Value;
                }
                if (Reader.LocalName=="tena_kood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>tena_kood");
                    }
                    clazz.TenaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tena_kood")).Value;
                }
                if (Reader.LocalName=="tehn_nait_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>tehn_nait_nimetu" +
                                "s");
                    }
                    clazz.TehnNaitNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tehn_nait_nimetus")).Value;
                }
                if (Reader.LocalName=="jrk_nr") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>jrk_nr");
                    }
                    clazz.JrkNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("jrk_nr")).Value;
                }
                if (Reader.LocalName=="lisavaartus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>lisavaartus");
                    }
                    clazz.Lisavaartus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lisavaartus")).Value;
                }
                if (Reader.LocalName=="seotud") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>seotud");
                    }
                    clazz.Seotud = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("seotud")).Value;
                }
                if (Reader.LocalName=="date_created") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>date_created");
                    }
                    clazz.DateCreated = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("date_created")).Value;
                }
                if (Reader.LocalName=="valistav") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>valistav");
                    }
                    clazz.Valistav = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valistav")).Value;
                }
                if (Reader.LocalName=="id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOsaAndmed_response>EN_EhitiseOsaAndmed>ehitise_osa>id");
                    }
                    clazz.Id = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("id")).Value;
                }
            }
        }
    }
}
